// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: Yang qiuyou wangyi168359476@163.com
 * @Date: 2024-07-16 15:16:31
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-12 15:10:46
 * @FilePath: \SGFEM\Import\NastranBDF\test\Coordinate\CORD1CParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Coordinate/CORD1CParser.h"

#include <gtest/gtest.h>

#include "Utility/FileSystem/SGFileSystem.h"

#include "DataStructure/Input/Coordinate/CORD1CData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Coordinate/ICORD1CService.h"
#include "DBManager/IService/Input/Node/INodeService.h"

#include "Import/BDFImport/BDFParserBase.h"
#include "Import/BDFImport/BulkData/Node/GRIDParser.h"
using namespace SG::DBManager;
using namespace SG::Import;

using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CORD1CParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CORD1CParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "GRID           1             10.     15.      8." };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseGRID (DB_SERVICEFACTORY, dividedEntryInfo);
    Entry = { "GRID           2             20.     32.     45." };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseGRID (DB_SERVICEFACTORY, dividedEntryInfo);
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    Entry = { "GRID           3             12.     16.      5." };
    SG::Import::BDF::BULKDATA::ParseGRID (DB_SERVICEFACTORY, dividedEntryInfo);

    ASSERT_TRUE (3 == DB_SERVICEFACTORY->get<INodeService> ()->Size ());

    Entry = { "CORD1C       100       1       2       3" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCORD1C (DB_SERVICEFACTORY, dividedEntryInfo);

    SG::DataStructure::FEM::CORD1CData data;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<ICORD1CService> ()->FindById (100, _OUT data)
                 == SG::DataStructure::Common::Status::STATUS_Success);  // equal

    // std::vector<SG::DataStructure::Common::Id> ids;
    ASSERT_EQ (1, DB_SERVICEFACTORY->get<ICORD1CService> ()->Size ());
}
